package com.info33.platform.system.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.info33.platform.common.mvc.controller.BaseController;
import com.info33.platform.common.mvc.vo.Result;
import com.info33.platform.system.dto.SysScheduleDTO;
import com.info33.platform.system.entity.SysSchedule;
import com.info33.platform.system.service.SysScheduleService;
import com.info33.platform.system.vo.SysScheduleVO;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @author admin
 */
@RestController
@RequestMapping("/SysSchedule")
@Api(tags = "系统 - 工作日历")
public class SysScheduleController extends BaseController<SysScheduleService, SysSchedule> {

    private final SysScheduleService sysScheduleService;

    @Autowired
    public SysScheduleController(SysScheduleService sysScheduleService) {
        super(sysScheduleService);
        this.sysScheduleService = sysScheduleService;
    }
    
    @PostMapping("/saveSchedule")
    @ApiOperation(value = "添加日程信息")
    public Result<?> saveSchedule(@RequestBody SysScheduleDTO sysScheduleDTO) {
        return sysScheduleService.saveSchedule(sysScheduleDTO, getCurrentUser());
    }
    
    @PostMapping("/editSchedule")
    @ApiOperation(value = "修改日程信息")
    public Result<?> editSchedule(@RequestBody SysScheduleDTO sysScheduleDTO) {
        return sysScheduleService.editSchedule(sysScheduleDTO, getCurrentUser());
    }
    
    @PostMapping(value = "/pageSchedule/{pageNum}/{pageSize}")
    @ApiOperation(value = "分页获取日程信息列表")
    public Result<IPage<SysScheduleVO>> pageSchedule(@RequestBody SysScheduleDTO sysScheduleDTO, @PathVariable int pageNum, @PathVariable int pageSize) {
        IPage<SysScheduleVO> page = new Page<SysScheduleVO>(pageNum, pageSize);
        return Result.ok(sysScheduleService.pageSchedule(page, sysScheduleDTO, getCurrentUser()));
    }
    
    @GetMapping(value = "/getDetail/{id}")
    @ApiOperation(value = "获取日程信息详情")
    public Result<SysScheduleVO> getDetail(@PathVariable Long id) {
        return Result.ok(sysScheduleService.getDetail(id, getCurrentUser()));
    }
    
    @GetMapping(value = "/finishSchedule/{id}")
    @ApiOperation(value = "完成日程信息")
    public Result<?> finishSchedule(@PathVariable Long id) {
        return sysScheduleService.finishSchedule(id, getCurrentUser());
    }
    
    @GetMapping(value = "/listSchedule/{startDate}/{endDate}")
    @ApiOperation(value = "获取一段时间内日程信息列表")
    public Result<List<SysScheduleVO>> listSchedule(@PathVariable String startDate, @PathVariable String endDate) {
        return Result.ok(sysScheduleService.listSchedule(startDate, endDate, getCurrentUser()));
    }
    
    @PostMapping(value = "/finishCreate")
    @ApiOperation(value = "完成日程信息 -- 创建者状态")
    public Result<?> finishCreate(@RequestBody List<Long> ids) {
        return sysScheduleService.finishCreate(ids, getCurrentUser());
    }
    
    @GetMapping(value = "/listScheduleDate/{startDate}/{endDate}")
    @ApiOperation(value = "根据开始与结束日期获取有日程的日期列表")
    public Result<List<String>> listScheduleDate(@PathVariable String startDate, @PathVariable String endDate) {
        return Result.ok(sysScheduleService.listScheduleDate(startDate, endDate, getCurrentUser()));
    }

}